package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhFeedback;
import com.ruoyi.system.service.IZhFeedbackService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.common.domain.ZhDeptInfo;

/**
 * 意见反馈 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-06-27
 */
@Controller
@RequestMapping("/system/zhFeedback")
public class ZhFeedbackController extends BaseController
{
    private String prefix = "system/zhFeedback";

	@Autowired
	private IZhFeedbackService zhFeedbackService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhFeedback:view")
	@GetMapping()
	public String zhFeedback(ZhFeedback zhFeedback,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhFeedback.getParams())));
		return prefix + "/zhFeedback";
	}

	/**
	 * 查询意见反馈列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhFeedback:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhFeedback zhFeedback)
	{
		startPage();
        List<ZhFeedback> list = zhFeedbackService.selectZhFeedbackList(zhFeedback);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出意见反馈列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhFeedback:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhFeedback zhFeedback)
    {
    	List<ZhFeedback> list = zhFeedbackService.selectZhFeedbackList(zhFeedback);
        ExcelUtil<ZhFeedback> util = new ExcelUtil<ZhFeedback>(ZhFeedback.class);
        return util.exportExcel(list, "zhFeedback");
    }
	
	/**
	 * 新增意见反馈
	 */
	@RequiresPermissions("system:zhFeedback:add")
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	public String add(ZhFeedback zhFeedback,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhFeedback.getParams())));
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存意见反馈
	 */

	@Log(title = "意见反馈", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhFeedback zhFeedback)
	{
		zhFeedback.setIfFinish(0);
		return toAjax(zhFeedbackService.insertZhFeedback(zhFeedback));
	}

	/**
	 * 修改意见反馈
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhFeedback:edit")
	@GetMapping("/edit/{id}")
	public String edit(ZhFeedback zhFeedback,@PathVariable("id") Integer id, ModelMap mmap)
	{
		ZhFeedback result = zhFeedbackService.selectZhFeedbackById(id);
		mmap.put("zhFeedback", result);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhFeedback.getParams())));
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存意见反馈
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhFeedback:edit")
	@Log(title = "意见反馈", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhFeedback zhFeedback)
	{		
		return toAjax(zhFeedbackService.updateZhFeedback(zhFeedback));
	}
	
	/**
	 * 删除意见反馈
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhFeedback:remove")
	@Log(title = "意见反馈", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhFeedback zhFeedback,String ids)
	{		
		return toAjax(zhFeedbackService.deleteZhFeedbackByIds(ids));
	}



	@GetMapping("feedback")
	public String feedback(ZhFeedback zhFeedback,ModelMap mmap)
	{
		return prefix + "/feedback";
	}

	@Log(title = "", businessType = BusinessType.UPDATE)
	@PutMapping("/finish/{id}")
	@ResponseBody
	public AjaxResult setDelivery(@PathVariable("id")int id){
		zhFeedbackService.setFinished(id);
		return AjaxResult.success("");
	}
}
